//
//  ID3v2Tag.h
//  MantuPlay
//
//  Created by Markus Sintonen on 12.4.2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>

enum FrameType { NotSupportedType = 0x00,
				 TitleType = 0x1,
				 ArtistType = 0x2,
				 AlbumType = 0x4,
				 GenreType = 0x8,
				 TrackNumberType = 0x10,
				 PartOfSetType = 0x20,
				 AlbumArtType = 0x40 };

static const int textFrameTypes = TitleType | ArtistType | AlbumType | GenreType | TrackNumberType | PartOfSetType;
static const int allFrameTypes = TitleType | ArtistType | AlbumType | GenreType | TrackNumberType | AlbumArtType | PartOfSetType;

@interface ID3TagReader : NSObject {
	NSString *title;
	NSString *artist;
	NSString *album;
	NSString *genre;
	NSNumber *trackNumber;
	NSData *albumArtData;
	NSNumber *partOfSet;
	
	int frameTypesToRead;
	
	//ID3 header stuff
	int majorVersion;
	BOOL usesUnsynchronisation;
	unsigned int framesDataSize;
	unsigned int framesDataPosition;
}

@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *artist;
@property (nonatomic, retain) NSString *album;
@property (nonatomic, retain) NSString *genre;
@property (nonatomic, retain) NSNumber *trackNumber;
@property (nonatomic, retain) NSData *albumArtData;
@property (nonatomic, retain) NSNumber *partOfSet;

-(id)initWithFile:(const char *)file framesToRead:(int)frameTypes;
-(void)parseFramesData:(unsigned char*)data;
-(BOOL)readHeaderFromData:(unsigned char*)data;
+(BOOL)findHeader:(unsigned char*)data;
+(unsigned int)getUInt:(unsigned char*)data;
+(unsigned int)getUInt:(unsigned char*)data length:(unsigned int)len;
+(unsigned int)getUnsynchsafeUInt:(unsigned char*)data;
+(unsigned int)getUnsynchsafeUInt:(unsigned char*)data length:(unsigned int)len;
+(unsigned int)convertToUnsynchronizedData:(unsigned char*)data dataLength:(unsigned int)len;
+(FrameType)getFrameTypeFromFrameID:(char*)frameID tagVersion:(int)version;
+(BOOL)isValidFrameID:(unsigned char*)data;
+(unsigned int)frameHeaderSizeForTagVersion:(unsigned int)version;
+(NSString*)stringFromTextFrameData:(unsigned char*)data length:(unsigned int)len;
+(NSString*)updateGenreFromGenreString:(NSString*)genreStr;
+(NSNumber*)updateTrackNumberFromTrackNumberString:(NSString*)trackNumberStr;
+(NSData*)imageDataFromFrameData:(unsigned char*)data length:(unsigned int)len;
@end